package com.pro.controller;

import com.pro.pojo.*;
import com.pro.service.JsMicrocircleService;
import com.pro.utils.GuavaUtils;
import com.pro.utils.SensitiveWordsUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
* @Title: 微圈控制层
* @Package com.pro.controller
* @author 许振杰
* @date 2022/1/7 0007
* @version V1.0
*/

@Controller
@RequestMapping(value = "/microcircle")
public class JsMicrocircleController {
    @Autowired
    private JsMicrocircleService jsMicrocircleService;

    //缓存工具类
    @Autowired
    private GuavaUtils guavaUtils;

    //铭感词过滤
    private SensitiveWordsUtil wordsUtil;

    //微圈树
    @RequestMapping("/getMicrocircleZtree")
    @ResponseBody
    public JsonData getMicrocircleZtree(){
        List<JsActicleCategroy> microcircleZtree = jsMicrocircleService.getMicrocircleZtree();
        return microcircleZtree !=null ? JsonData.buildSuccess(microcircleZtree) : JsonData.buildError("服务器出错了");
    }

    //树节点的添加
    @RequestMapping("/addZtreeNode")
    @ResponseBody
    public JsonData addZtreeNode(String artcleCategroyName, String createId,  String createDate, Integer parentId){
        boolean addZtreeNode = jsMicrocircleService.addZtreeNode(artcleCategroyName, createId, createDate, parentId);
        return addZtreeNode ? JsonData.buildSuccess(addZtreeNode) : JsonData.buildError("服务器出错了");
    }

    //树节点删除
    @RequestMapping("/delZtreeNode")
    @ResponseBody
    public JsonData delZtreeNode(Integer acticleCategroyId){
        boolean delZtreeNode = jsMicrocircleService.delZtreeNode(acticleCategroyId);
        return delZtreeNode ? JsonData.buildSuccess(delZtreeNode) : JsonData.buildError("服务器出错了");
    }

    //树节点修改
    @RequestMapping("/editZtreeNode")
    @ResponseBody
    public JsonData editZtreeNode(Integer acticleCategroyId ,String artcleCategroyName,String updateId,String updateDate){
        boolean ztreeNode = jsMicrocircleService.editZtreeNode(acticleCategroyId, artcleCategroyName, updateId, updateDate);
        return ztreeNode ? JsonData.buildSuccess(ztreeNode) : JsonData.buildError("服务器出错了");
    }

    //点击树节点展示对应分类
    @RequestMapping("/getMicrocircleZtreeById")
    @ResponseBody
    public JsonData getMicrocircleZtreeById(Integer acticleCategroyId,Integer details){
        List<JsActicleCategroy> microcircleZtreeById = jsMicrocircleService.getMicrocircleZtreeById(acticleCategroyId,details);
        return microcircleZtreeById!=null? JsonData.buildSuccess(microcircleZtreeById):JsonData.buildError("服务器出错了");
    }

    //微圈列表
    @RequestMapping(value = "/getMicrocircleTable")
    @ResponseBody
    public JsonData getMicrocircleTable(Integer details){
        List<JsMicrocircle> microcircleTable = jsMicrocircleService.getMicrocircleTable(details);
        return microcircleTable!=null? JsonData.buildSuccess(microcircleTable):JsonData.buildError("服务器出错了");
    }

    //微圈列表的模糊查
    @RequestMapping(value = "/getMicrocircleSearch")
    @ResponseBody
    public JsonData getMicrocircleSearch(Integer details,String artcleTitle , String userName,String account){
        List<JsActicleCategroy> microcircleSearch = jsMicrocircleService.getMicrocircleSearch(details,artcleTitle, userName, account);
        return microcircleSearch != null? JsonData.buildSuccess(microcircleSearch):JsonData.buildError("服务器出错了");
    }

    //微圈的查看
    @RequestMapping(value = "/getMicrocircleBymicrocircleId")
    @ResponseBody
    public JsonData getMicrocircleBymicrocircleId(Integer microcircleId){
        JsMicrocircle microcircleBymicrocircleId = jsMicrocircleService.getMicrocircleBymicrocircleId(microcircleId);
        return microcircleBymicrocircleId != null? JsonData.buildSuccess(microcircleBymicrocircleId):JsonData.buildError("服务器出错了");
    }

    //微圈的删除
    @RequestMapping(value = "/delMicrocircleBymicrocircleId")
    @ResponseBody
    public JsonData delMicrocircleBymicrocircleId(Integer microcircleId){
        boolean delMicrocircleBymicrocircleId = jsMicrocircleService.delMicrocircleBymicrocircleId(microcircleId);
        return delMicrocircleBymicrocircleId ? JsonData.buildSuccess(delMicrocircleBymicrocircleId) : JsonData.buildError("服务器出错了");
    }

    //删除微圈对应评论
    @RequestMapping(value = "/delMicrocircleComment")
    @ResponseBody
    public JsonData delMicrocircleComment(Integer commodityId){
        boolean comment = jsMicrocircleService.delMicrocircleComment(commodityId);
        return comment ? JsonData.buildSuccess(comment) : JsonData.buildError("服务器出错了");
    }

    /**
    * @Title: 微圈添加
    * @author 许振杰
    * @date 2022/1/11 0011 11:58
    * @version V1.0
    */
    @RequestMapping(value = "/addMicrocircle")
    @ResponseBody
    public JsonData addMicrocircle(JsMicrocircle microcircle){
        boolean addMicrocircle = jsMicrocircleService.addMicrocircle(microcircle);
        return addMicrocircle ? JsonData.buildSuccess(addMicrocircle) : JsonData.buildError("服务器出错了");
    }

    /**
    * @Title: 微圈审核记录的添加
    * @author 许振杰
    * @date 2022/1/11 0011 21:15
    * @version V1.0
    */
    @RequestMapping(value = "/addCourseRecord")
    @ResponseBody
    public JsonData addCourseRecord(JsCourseRecord courseRecord){
        boolean addCourseRecord = jsMicrocircleService.addCourseRecord(courseRecord);
        return addCourseRecord ? JsonData.buildSuccess(addCourseRecord) : JsonData.buildError("服务器出错了");
    }

    /**
    * @Title: 微圈审核的删除
    * @author 许振杰
    * @date 2022/1/13 0013 15:25
    * @version V1.0
    */
    @RequestMapping(value = "/delCourseRecord")
    @ResponseBody
    public JsonData delCourseRecord(Integer courseId,Integer type){
        boolean delCourseRecord = jsMicrocircleService.delCourseRecord(courseId, type);
        return delCourseRecord ? JsonData.buildSuccess(delCourseRecord) : JsonData.buildError("服务器出错了");
    }

    /**
    * @Title: 根据details的状态获取微圈信息
    * @author 许振杰
    * @date 2022/1/12 0012 16:35
    * @version V1.0
    */
    @RequestMapping(value = "/getMicrocircleBydetails")
    @ResponseBody
    public JsonData getMicrocircleBydetails(Integer details){
        List<JsMicrocircle> microcircleBydetails = jsMicrocircleService.getMicrocircleBydetails(details);
        return microcircleBydetails != null ? JsonData.buildSuccess(microcircleBydetails): JsonData.buildError("服务器出错了");
    }


    /**
    * @Title: 微圈草稿的修改
    * @author 许振杰
    * @date 2022/1/12 0012 16:01
    * @version V1.0
    */
    @RequestMapping(value = "/editMicrocircle")
    @ResponseBody
    public JsonData editMicrocircle(JsMicrocircle microcircle){
        boolean editMicrocircle = jsMicrocircleService.editMicrocircle(microcircle);
        return editMicrocircle ? JsonData.buildSuccess(editMicrocircle) : JsonData.buildError("服务器出错了");

    }

    /**
    * @Title: 微圈状态信息的修改 details改为已提交
    * @author 许振杰
    * @date 2022/1/12 0012 21:24
    * @version V1.0
    */
    @RequestMapping(value = "/editMicrocircleBymicrocircleId")
    @ResponseBody
    public JsonData editMicrocircleBymicrocircleId(Integer microcircleId,String releaseDate,Integer details){
        boolean editMicrocircleBymicrocircleId = jsMicrocircleService.editMicrocircleBymicrocircleId(microcircleId, releaseDate, details);
        return editMicrocircleBymicrocircleId ? JsonData.buildSuccess(editMicrocircleBymicrocircleId) : JsonData.buildError("服务器出错了");
    }

    //添加微圈操作日志
    @RequestMapping(value = "/addMicrocircleLog")
    @ResponseBody
    public JsonData addMicrocircleLog(JsLog log){
        boolean addMicrocircleLog = jsMicrocircleService.addMicrocircleLog(log);
        return addMicrocircleLog ? JsonData.buildSuccess(addMicrocircleLog) : JsonData.buildError("服务器出错了");
    }

    //查看微圈对应评论
    @RequestMapping(value = "/getMicrocircleComment")
    @ResponseBody
    public JsonData getMicrocircleComment(Integer commodityId,Integer type,Integer userType){
        List<JsComment> microcircleComment = jsMicrocircleService.getMicrocircleComment(commodityId, type, userType);
        return microcircleComment != null? JsonData.buildSuccess(microcircleComment):JsonData.buildError("服务器出错了");
    }

    //查看对应微圈的评论数量
    @RequestMapping(value = "/getMicrocircleCommentNum")
    @ResponseBody
    public JsonData getMicrocircleCommentNum(Integer commodityId,Integer type){
        Integer microcircleCommentNum = jsMicrocircleService.getMicrocircleCommentNum(commodityId, type);
        return microcircleCommentNum != null ? JsonData.buildSuccess(microcircleCommentNum) : JsonData.buildError("服务器出错了");
    }

    //添加一条评论
    @RequestMapping(value = "/addMicrocircleComment")
    @ResponseBody
    public JsonData addMicrocircleComment(JsComment comment){
        String content = comment.getContent();
        String filter = wordsUtil.getFilter(content);
        comment.setContent(filter);
        boolean b = jsMicrocircleService.addMicrocircleComment(comment);
        return b ? JsonData.buildSuccess(b) : JsonData.buildError("服务器出错了");
    }

    //隐藏显示评论
    @RequestMapping(value = "/editDisplay")
    @ResponseBody
    public JsonData editDisplay(JsComment comment){
        boolean editDisplay = jsMicrocircleService.editDisplay(comment);
        return editDisplay ? JsonData.buildSuccess(editDisplay) : JsonData.buildError("服务器出错了");
    }

    //删除评论
    @RequestMapping(value = "/deleteComment")
    @ResponseBody
    public JsonData deleteComment(Integer id){
        boolean deleteComment = jsMicrocircleService.deleteComment(id);
        return deleteComment ? JsonData.buildSuccess(deleteComment) : JsonData.buildError("服务器出错了");
    }

    /**
    * @Title: 删除微圈对应评论
    * @author 许振杰
    * @date 2022/1/14 0014 9:48
    * @version V1.0
    */
    @RequestMapping(value = "/delCommentByCommodityId")
    @ResponseBody
    public JsonData delCommentByCommodityId(Integer commodityId,Integer type){
        boolean delCommentByCommodityId = jsMicrocircleService.delCommentByCommodityId(commodityId, type);
        return delCommentByCommodityId ? JsonData.buildSuccess(delCommentByCommodityId) : JsonData.buildError("服务器出错了");
    }

    /**
    * @Title: 个人微圈列表
    * @author 许振杰
    * @date 2022/1/13 0013 19:06
    * @version V1.0
    */
    @RequestMapping(value = "/personalMicrocircle")
    @ResponseBody
    public JsonData personalMicrocircle(Integer userId){
        List<JsMicrocircle> jsMicrocircles = jsMicrocircleService.personalMicrocircle(userId);
        return jsMicrocircles != null ? JsonData.buildSuccess(jsMicrocircles) : JsonData.buildError("服务器出错了");
    }

    /**
    * @Title: 个人微圈的模糊查询
    * @author 许振杰
    * @date 2022/1/13 0013 21:56
    * @version V1.0
    */
    @RequestMapping(value = "/personalMicrocircleSearch")
    @ResponseBody
    public JsonData personalMicrocircleSearch(JsMicrocircle microcircle){
        List<JsMicrocircle> jsMicrocircles = jsMicrocircleService.personalMicrocircleSearch(microcircle);
        return jsMicrocircles != null ? JsonData.buildSuccess(jsMicrocircles) : JsonData.buildError("服务器出错了");
    }

    /**
    * @Title: 微圈操作日志列表
    * @author 许振杰
    * @date 2022/1/14 0014 11:35
    * @version V1.0
    */
    @RequestMapping(value = "/getMicrocirclLog")
    @ResponseBody
    public JsonData getMicrocirclLog(Integer logType){
        List<JsLog> microcirclLog = jsMicrocircleService.getMicrocirclLog(logType);
        return microcirclLog != null ? JsonData.buildSuccess(microcirclLog) : JsonData.buildError("服务器出错了");
    }

    /**
    * @Title: 个人微圈模糊查询
    * @author 许振杰
    * @date 2022/1/14 0014 14:05
    * @version V1.0
    */
    @RequestMapping(value = "/getMicrocirclLogSearch")
    @ResponseBody
    public JsonData getMicrocirclLogSearch(com.pro.pojo.JsLog log){
        List<JsLog> microcirclLogSearch = jsMicrocircleService.getMicrocirclLogSearch(log);
        return microcirclLogSearch != null ? JsonData.buildSuccess(microcirclLogSearch) : JsonData.buildError("服务器出错了");
    }

    /**
    * @Title: 个人微圈操作记录的删除
    * @author Administrator
    * @date 2022/1/14 0014 15:29
    * @version V1.0
    */
    @RequestMapping(value = "/delMicrocirclLog")
    @ResponseBody
    public JsonData delMicrocirclLog(Integer logId){
        boolean delMicrocirclLog = jsMicrocircleService.delMicrocirclLog(logId);
        return delMicrocirclLog ? JsonData.buildSuccess(delMicrocirclLog) : JsonData.buildError("服务器出错了");
    }
}
